package com.yingxin.yx.framework.commons.dto;

import com.yingxin.yx.framework.commons.constant.PathConst;
import com.yingxin.yx.framework.commons.helper.PropertiesHelper;
import com.yingxin.yx.framework.render.core.RenderColumn;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Map;

@Data
public class AttachmentDto implements Serializable {

    @RenderColumn(name = "attachmentId", sort = 1)
    @ApiModelProperty(value = "附件id")
    private String attachmentId;

    @RenderColumn(name = "attachmentName", sort = 2)
    @ApiModelProperty(value = "名称")
    private String attachmentName;

    @ApiModelProperty(value = "path")
    private String attachmentPath;

    @ApiModelProperty(value = "附件uri")
    private String attachmentUrl;

    private String businessId;

    private String businessType;

    private String businessAttr;

    private Map<String,String> invoiceMap;

    public AttachmentDto() {
    }

    public AttachmentDto(String attachmentId, String attachmentName, String attachmentPath) {
        this.attachmentId = attachmentId;
        this.attachmentName = attachmentName;
        this.attachmentPath = attachmentPath;
    }

    public void addBizInfo(String businessId, String businessType, String businessAttr) {
        this.businessId = businessId;
        this.businessType = businessType;
        this.businessAttr = businessAttr;
    }


    @RenderColumn(name = "attachmentUrl", sort = 3, field = "attachmentUrl")
    public String getAttachmentUrl() {
        String contextPath = PropertiesHelper.getInstance().getProperty(PathConst.CONTEXT_PATH);
        if (StringUtils.isNotBlank(contextPath)) {
            return contextPath + attachmentPath;
        }
        return attachmentPath;
    }

}